import React, { useState, useEffect } from 'react';
import { Form, Select, Button, Input, DatePicker } from 'antd';
import FuzzyQueryStore from '@/components/FuzzyQueryStore'
import { getzjfstoreList } from '../service'
import { customTrimFunc } from '@/utils/utils.jsx';

const { RangePicker } = DatePicker;
const { Option } = Select;

export default ({ type, query, status, handleOk, handleCancel }) => {
  const [form] = Form.useForm();
  
  const [storeName, setStoreName] = useState('');

  useEffect(()=>{
    form.resetFields();
  },[query])

  useEffect(()=>{
    setStoreName('');
  },[type])

  //查询
  const onFinish = (values) => {
    handleOk(customTrimFunc(values));
  };

  //重置
  const onReset = () => {
    setStoreName('');
    form.resetFields();
    handleCancel()
  };

  return (
    <Form
      onFinish={onFinish}
      form={form}
      className='search-form-style'
      name="vip-price-form"
      style={{marginBottom:12}}
      initialValues={{...query}}
    >
     <Form.Item label="供应商" name={(type == 6 || type == 7 || type == 8) ? 'storeId' : "zjfStorePk"}>
       <FuzzyQueryStore storeName={storeName} queryData={getzjfstoreList} onChange={(val, index, obj) => setStoreName(obj.storeName)} width={140}/>
      </Form.Item>

      <Form.Item label="商品" name={type == 8 ? 'name' : (type == 6 || type == 7 ? 'goodsName' : 'zjfGoodsCommonName')}>
        <Input placeholder="请输入商品名称" style={{width:140}}/>
      </Form.Item>

      {
        type == 7 && (<>
          <Form.Item label="商品编码" name="outStoreSku">
            <Input placeholder="请输入商品编码" />
          </Form.Item>
          <Form.Item label="款式编码" name="outStoreSpu">
            <Input placeholder="请输入款式编码" />
          </Form.Item>
        </>)
      }

      {
        ['1', '2', '3', '4', '8'].includes(type) && (<Form.Item label="申请时间" name="apply_time">
          <RangePicker format="YYYY-MM-DD HH:mm:ss" showTime style={{width: 360}}/>
        </Form.Item>)
      }

        {(['2', '3', '4', '6'].includes(type) || (type == 8 && status != 5)) && (
            <Form.Item label="审核时间" name="audit_time">
              <RangePicker format="YYYY-MM-DD HH:mm:ss" showTime style={{width: 360}}/>
            </Form.Item>
        )}

        {
          type == 7 &&(<>
            <Form.Item label="拿货员" name="deliverymanUserName">
              <Input placeholder="请输入拿货员账号或姓名" style={{width:140}}/>
            </Form.Item>
            <Form.Item label="发起人" name="taskUserName">
              <Input placeholder="请输入发起人账号或姓名" style={{width:140}}/>
            </Form.Item>
            <Form.Item label="生成时间" name="generation_time">
              <RangePicker format="YYYY-MM-DD HH:mm:ss" showTime style={{width:380}}/>
            </Form.Item>
          </>)
        }

        {
          type == 6 && (<>

          <Form.Item label="审核人" name="auditUserName">
            <Input placeholder="请输入审核人账号或姓名" style={{width:140}}/>
          </Form.Item>

          <Form.Item label="拿货员" name="deliverymanUserName">
            <Input placeholder="请输入拿货员账号或姓名" style={{width:140}}/>
          </Form.Item>

          <Form.Item label="发起人" name="taskUserName">
            <Input placeholder="请输入发起人账号或姓名" style={{width:140}}/>
          </Form.Item>

           <Form.Item label="状态" name="status">
              <Select style={{ width: '140px' }} placeholder='全部'>
                <Option value="1">使用中</Option>
                <Option value="2">审核失败</Option>
              </Select>
            </Form.Item>
          </>)
        }

        {
          (type == 8 && status != 5) && (<>
            <Form.Item label="审核人" name="auditor">
              <Input placeholder="请输入审核人账号" style={{width:140}}/>
            </Form.Item>
          </>)
        }

    {
          (type == 8) && (<>
            <Form.Item label="商品类别" name="platType">
              <Select style={{ width: '140px' }} placeholder='全部'>
                <Option value="0">网店商品</Option>
                <Option value="1">系统商品</Option>
              </Select>
            </Form.Item>
          </>)
        }


        <Form.Item >
          <Button type="primary" htmlType="submit" style={{ marginRight: '16px' }}>查询</Button>
          <Button onClick={onReset}>重置</Button>
        </Form.Item>
    </Form>
  );
};
